package com.example.app2;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.EditText;

public class Activity_score extends AppCompatActivity {
    int score1 = 0,score2 = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_score);
    }

    @Override    //Activity结束前保存数据
    public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
        String scoreA = ((EditText)findViewById(R.id.Score1)).getText().toString();
        String scoreB = ((EditText)findViewById(R.id.Score2)).getText().toString();

        outState.putString("scoreA",scoreA);
        outState.putString("scoreB",scoreB);
    }

    @Override    //Activity结束后返回数据
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        String restore_score1 = savedInstanceState.getString("scoreA");
        String restore_score2 = savedInstanceState.getString("scoreB");

        ((EditText)findViewById(R.id.Score1)).setText(restore_score1);
        ((EditText)findViewById(R.id.Score2)).setText(restore_score2);

    }

    public void show(){
        EditText scoreA = findViewById(R.id.Score1);
        scoreA.setText(String.valueOf(score1));
    }
    public void show2(){
        EditText scoreB = findViewById(R.id.Score2);
        scoreB.setText(String.valueOf(score2));
    }
    public void clear(){
        show();
        show2();
    }



    public void button1(View v){
        score1 += 3;
        show();
    }
    public void button2(View v){
        score1 += 2;
        show();
    }
    public void button3(View v){
        score1 += 1;
        show();
    }
    public void button4(View v){
        score2 += 3;
        show2();
    }
    public void button5(View v){
        score2 += 2;
        show2();
    }
    public void button6(View v){
        score2 += 1;
        show2();
    }
    public void reset(View v){
        score1 = score2 = 0;
        clear();
    }
}